from django import http
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.urlresolvers import reverse

from accounts.sales.forms import SignupForm

def signup(request, signup_form=SignupForm, next=None):
	if request.method == 'POST':
		form = signup_form(request.POST)
		if form.is_valid():
			form.save()
			if next is None:
				return http.HttpResponseRedirect(reverse('accounts.sales.signup_complete'))
			else:
				return http.HttpResponseRedirect(next)
	else:
		form = signup_form(initial=request.GET.copy())
	return render_to_response('sales/signup.html', {'form':form},
		context_instance=RequestContext(request))